<?php
/**
 * Function
 * @package AGILSUN
 * @author Mr.Hao <haonguyen.agilsun@gmail.com>
 */
include_once ('include/get-post-function.php');
include_once ('include/remove-dashboard-items.php');
?>

<?php

/**
 * Setup Images Size
 */
function agilsun_imagesize() {
    add_theme_support('post-thumnails');
    add_image_size('msize', 216, 173, true); // medium size thumbnail
    add_image_size('ssize', 180, 275, true); // news slide size thumbnail
	add_image_size('psize', 500, 350, true); // project size thumbnail
    add_image_size('nsize', 705, 280, true); // news size thumbnail
}

add_action('after_setup_theme', 'agilsun_imagesize');

/**
 * Theme Options
 */
include_once("theme-options.php");

/**
 * Menu Locations
 */
if (function_exists('wp_nav_menu')) {
	function agilsun_wp_my_menus() {
		register_nav_menus(array(
				'main-menu' => __('Main menu'),
				'footer-menu' => __('Footer menu')
		));
	}
	add_action('init', 'agilsun_wp_my_menus');
}

/**
 * Featured images
 */
function agilsun_featured_images() {
	add_theme_support( 'post-thumbnails' );
}

add_action( 'after_setup_theme', 'agilsun_featured_images' );

/**
 * Register Note
 */
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' => __('Note'),
        'id' => 'note',
        'description' => 'Giới thiệu Agilsun trên trang home',
        'before_widget' => '<div class="home-referral col-md-4">',
        'after_widget' => '</div>',
        'before_title' => '<h1>',
        'after_title' => '</h1>'
    ));
}

/**
 * Register Right Sidebar
 */
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' => __('Right Sidebar', 'www.agilsun.com'),
        'id' => 'right-sidebar',
        'description' => 'Right Sidebar ở trang Tin Tức',
        'before_widget' => '<li>',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    ));
}

/**
 * Register PROJECTS post type
 * @author Mr.Hao <haonguyen.agilsun@gmail.com>
 */
function agilsun_create_project_post_type() {
	register_post_type('project',
		array(
			'labels'  =>  array(
			'name'  =>  __('Projects'),
			'singular_name' =>  __('Project'),
			'add_new' =>  __('Add New'),
			'add_new_item'  =>  __('Add New'),
			'edit'  =>  __('Edit Project'),
			'edit_item' =>  __('Edit Project'),
			'new_item'  =>  __('New Project'),
			'view'  =>  __('View Project'),
			'view_item' =>  __('View Project'),
			'search_items' =>  __('Search Project'),
			'not_found' =>  __('Project not found'),
			'not_found_in_trash'  =>  __('Project not found')
		),
		'public'  =>  true,
		'show_ui' =>  true,
		'publicy_queryable' =>  true,
		'exclude_from_search' =>  false,
		'menu_position' => 20,
		'hierarchical'  => false,
		'show_in_nav_menus' => true,
		'has_archive' => true,
		'query_var' =>  true,
		'supports'  =>  array(
			'title', 'editor', 'author', 'thumbnail'
			),
		'rewrite' =>  array('slug'  =>  'du-an', 'with_front' =>  false),
		'can_export'  =>  true,
		'description' =>  __('Project')
	));
}
add_action('init', 'agilsun_create_project_post_type');

/**
 * Register PROJECTS post type
 * @author Mr.Hao <haonguyen.agilsun@gmail.com>
 */
function agilsun_create_team_post_type() {
	register_post_type('team',
		array(
			'labels'  =>  array(
			'name'  =>  __('Team'),
			'singular_name' =>  __('Team Member'),
			'add_new' =>  __('Add New'),
			'add_new_item'  =>  __('Add New Team Member'),
			'edit'  =>  __('Edit Team Member'),
			'edit_item' =>  __('Edit Team Member'),
			'new_item'  =>  __('New Team Member'),
			'view'  =>  __('View Team Member'),
			'view_item' =>  __('View Team Member'),
			'search_items' =>  __('Search Team Member'),
			'not_found' =>  __('Team Member not found'),
			'not_found_in_trash'  =>  __('Team Member not found')
		),
		'public'  =>  true,
		'show_ui' =>  true,
		'publicy_queryable' =>  true,
		'exclude_from_search' =>  false,
		'menu_position' => 20,
		'hierarchical'  => false,
		'show_in_nav_menus' => true,
		'has_archive' => true,
		'query_var' =>  true,
		'supports'  =>  array(
			'title', 'editor', 'thumbnail'
			),
		'rewrite' =>  array('slug'  =>  'nhan-su', 'with_front' =>  false),
		'can_export'  =>  true,
		'description' =>  __('Team')
	));
}
add_action('init', 'agilsun_create_team_post_type');

/**
 * Custom post type icon
 */
function agilsun_admin_css() {?>
	<style type="text/css" media="screen">
		#menu-posts-project .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/projects.png) no-repeat 6px 7px!important;
			background-size: 17px 15px;
		}
		#menu-posts-project:hover .wp-menu-image, #menu-posts-project.wp-has-current-submenu .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/projects_rollover.png) no-repeat 6px 7px!important;
		}
		#menu-posts-team .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/team.png) no-repeat 6px 7px!important;
			background-size: 17px 15px;
		}
		#menu-posts-team:hover .wp-menu-image, #menu-posts-team.wp-has-current-submenu .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/team_rollover.png) no-repeat 6px 7px!important;
		}
		#toplevel_page_edit-post_type-acf .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/portfolio.png) no-repeat 6px 7px!important;
			background-size: 17px 15px;
		}
		#toplevel_page_edit-post_type-acf:hover .wp-menu-image, #toplevel_page_edit-post_type-acf.wp-has-current-submenu .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/portfolio_rollover.png) no-repeat 6px 7px!important;
		}
		#toplevel_page_revslider .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/showcase.png) no-repeat 6px 7px!important;
			background-size: 17px 15px;
		}
		#toplevel_page_revslider:hover .wp-menu-image, #toplevel_page_revslider.wp-has-current-submenu .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/showcase_rollover.png) no-repeat 6px 7px!important;
		}
		#toplevel_page_wpcf7 .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/faqs.png) no-repeat 6px 7px!important;
			background-size: 17px 15px;
		}
		#toplevel_page_wpcf7:hover .wp-menu-image, #toplevel_page_wpcf7.wp-has-current-submenu .wp-menu-image, #toplevel_page_wpcf7.current .wp-menu-image {
			background: url(<?php echo get_template_directory_uri(); ?>/img/wp/faqs_rollover.png) no-repeat 6px 7px!important;
		}
		#toplevel_page_wpcf7 .wp-menu-image img {
			display: none;
		}
		.wp_themeSkin iframe {
			background-color: #fff !important;
		}
	</style>
<?php
}
add_action( 'admin_head', 'agilsun_admin_css' );

/**
 * Phân trang
 */
function pagination($pages = '', $range = 4) {  
	$showitems = ($range * 2) + 1;  
 
	global $paged;
	 
	if(empty($paged)) $paged = 1;
 
	if($pages == '') {
		global $wp_query;
		$pages = $wp_query->max_num_pages;
		if(!$pages) {
			 $pages = 1;
		}
	}
 
	if(1 != $pages) {
		echo '<li class="news-page-split-page">';
		 
		echo '<span>';
		
		if ($paged > 1) {
			echo '<a href="' . get_pagenum_link($paged - 1) . '" class="news-page-arowleft sprite">  </a>';
		}
					
		for ($i=1; $i <= $pages; $i++) {
			if (1 != $pages &&( !($i >= $paged + $range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems )) {
				echo ($paged == $i) ? '<a href="' . get_pagenum_link($i) . '" class="active">' . $i . '</a>' : '<a href="' . get_pagenum_link($i) . '">' . $i . '</a>';
			}
		}
		
		if ($paged < $pages) {
			echo '<a href="' . get_pagenum_link($paged + 1) . '" class="news-page-arowright sprite">  </a>';
		}
		
		echo '</span>';
		
		echo "</li>\n";
	 }
}

/**
 * Comments
 */
function agilsun_comment($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment; ?>
	
	<li class="clearfix <?php if ($depth > 1) echo 'child'; ?>" id="comment-<?php comment_ID(); ?>">        		
		<h4 class="entry-title"><a href="#" class="title"><?php printf('%s', get_comment_author_link()) ?></a><i>đã nói:</i> <span class="date"><?php printf('%1$s ' . __("lúc") . ' %2$s', get_comment_date(),  get_comment_time()) ?></span></h4>
		
		<div class="arrow_box"><?php comment_text() ?></div>
        
        <div class="reply">
				<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __("<i class=\"icon-reply first-i\"></i>Trả lời"), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
		</div>
	
<?php
}

?>

